<?php /*a:2:{s:47:"D:\www\long_shop\app\view\dept\school_edit.html";i:1726979389;s:42:"D:\www\long_shop\app\view\common\head.html";i:1702389678;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/jquery/jquery-1.12.4.min.js"></script>    
    <link href="/static/bst5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="/static/bst5.3.2/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="/static/bst-icons/font/bootstrap-icons.css">
    <script src="/static/layer/layer/layer.js"></script>
    <link rel="stylesheet" href="/static/css/my.css">    
</head>
<head>
<title>商家资料编辑</title>
<!-- <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=NVVBZ-4IMKV-YAGPI-5CZCE-6JHZK-OXBZJ"></script> -->
<script type="text/javascript" src="https://api.tianditu.gov.cn/api?v=4.0&tk=9fa6511a99dc9ae93730fa573eb265be"></script>
<style>
  imgx{border:1px solid #ccc ;}
</style>
</head>
<body style="">
    <div class="container p-3 my-3 " style="max-width: 800px;position:relative;"  >

    <h2>商家资料编辑</h2><br/>

     <form method="post" action="/index.php/dept/edit" enctype="multipart/form-data"> 

      <input type="hidden" name="id" id="id" value="<?php echo htmlentities($data['id']); ?>" />
      <input type="hidden" name="real_key"  value="<?php echo htmlentities($data['info']['id']); ?>" />

      <div class="mb-3 row">
        <div class="col-2"><label for="name" class="form-label">商家名称:</label></div>
        <div class="col-10"><input type="text" class="form-control" id="name" name="name" value="<?php echo htmlentities($data['name']); ?>"  /></div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><lable for="title" class="form-label">商家简介:</label></lable></div>
        <div class="col-10"><input type="text" class="form-control" id="title" name="title" value="<?php echo htmlentities($data['title']); ?>"  /></div>
      </div>
      <div class="mb-3 row">
        <div class="col-2"><lable for="shop_img" class="form-label">商家形象图:</label></lable></div>
        <div class="col-10">
          <img class="thumb" style="width:70px" src="<?php echo htmlentities($data['info']['shop_img']); ?>"  />
          <input type="file" id="shop_img" name="shop_img" value=""  />
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2">
          <label for="file" class="form-label">商家轮播图:</label>
        </div>
        <div class="col" style="display: flex;">
          <?php foreach($data['ad_img'] as $image): ?>
            <div style="border:1px solid #ccc;text-align: center;margin-right:2px;">
                <img class="thumb" src="<?php echo htmlentities($image); ?>" style="width:70px;" />
                <span class="bi-x-lg img_remove" row_id="<?php echo htmlentities($data['info']['id']); ?>" src="<?php echo htmlentities($image); ?>" title="删除图片" style="cursor: pointer;"></span>
            </div>
          <?php endforeach; ?>

            <div >
              <button id="img_add" type="button" class="btn btn-info"><span class="bi-plus-lg" ></span></button>
            </div>
            <input id="file1" type="file"  name="file1" style="display: none;" />
        </div>
      </div>  


      <div class="mb-3 row">
        <div class="col-2"><lable for="bus_license_img" class="form-label">营业执照:</label></lable></div>
        <div class="col-10">
          <img class="thumb" style="width:70px" src="<?php echo htmlentities($data['info']['bus_license_img']); ?>"  />
          <input type="file" id="bus_license_img" name="bus_license_img" value=""  />
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="city" class="form-label">城市:</label></div>
        <div class="col-10"><input type="text" class="form-control" id="city" name="city" value="<?php echo htmlentities($data['info']['city']); ?>"  /></div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="address" class="form-label">地址:</label></div>
        <div class="col-10"><input type="text" class="form-control" id="address" name="address" value="<?php echo htmlentities($data['info']['address']); ?>"  /></div>
      </div>      

      <div class="mb-3 row">
        <div class="col-2"><label for="latlng" class="form-label">地图坐标:</label></div>
        <div class="col-5"><input type="text" class="form-control" id="lat" name="lat" value="<?php echo htmlentities($data['info']['lat']); ?>"  /></div>
        <div class="col-5"><input type="text" class="form-control" id="lng" name="lng" value="<?php echo htmlentities($data['info']['lng']); ?>"  /></div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="user_id" class="form-label">负责人:<b id="new_user_id"></b></label></div>
        <div class="col-10">
          <div class="input-group">
          <input type="hidden" class="form-control" id="user_id" name="user_id" value="<?php echo htmlentities($data['user_id']); ?>" /></c>
          <input type="text" class="form-control" id="user_id_name" value="<?php echo htmlentities($data['user_id_name']); ?>" placeholder="姓名或者手机号码" /></c>
          <button type="button" id="find_user" class="btn btn-info  bi-search" >查找</button>
          </div>
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><lable for="" class="form-label">法人证件:</label></lable></div>
        <div class="col-10">
          <img class="thumb" style="width:70px" src="<?php echo htmlentities($data['info']['id_img']); ?>"  />
          <input type="file" id="id_img" name="id_img" value=""  />
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="mobile" class="form-label">联系电话:</label></div>
        <div class="col-10"><input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo htmlentities($data['info']['mobile']); ?>"  /></div>
      </div>
       
      <div class="mb-3 row">
        <div class="col-2"><label for="status" class="form-label">是否开启:</label></div>
        <div class="col-10">
          <input type="radio" class="form-check-input" id="radio3" name="status" value="1" <?php if($data['status']==1): ?> checked <?php endif; ?>/> 
          <label class="form-check-label" for="radio3">开启</label>
          <input type="radio" class="form-check-input" id="radio4" name="status" value="2" <?php if($data['status']==2): ?> checked <?php endif; ?>/>
          <label class="form-check-label" for="radio4">关闭</label>
        </div>
      
       </div>

      <button  type="button" class="btn btn-primary" onclick="doSave()">保存(Save)</button>

    </form>
    </div>


    <div id="mapContainer" style="position:absolute;width:98%; height:90%;left:1%;top:1%;border:1px solid #666;box-shadow:0 0 3px #555;background: #f7f7f7;display: none;">
      <div style="padding: 4px;">
        地图坐标选取器 &nbsp;关键字：<input id="area" type="text"/>&nbsp;<button type="button" onclick="area_serarch()">搜索</button>&nbsp;&nbsp;
        lng:<input id="lngX" type="text" />
        lat:<input id="latX" type="text" />
        &nbsp;<button type="button" onclick="close_map()">关闭</button>
      </div>
      <div id="mapDiv" style="border-top: 1px solid #ccc;height: 90%;">AAA</div>
      <div style="border-top: 1px solid #ccc;padding: 4px;">
        <c id="detailedAddress"></c>
        <c id="addressMsg"></c>
      </div>
    </div>


<script type="text/javascript">
    var map;
    var lnglat;
    var zoom = 8;
    var marker;

    //坐标解析
    var geocode; 

    function t_map(){
        //创建地图
        map = new T.Map('mapDiv');
        lnglat = new T.LngLat(121.4096,28.61943);
        map.centerAndZoom(lnglat, zoom);

        //向地图上添加标注
        marker = new T.Marker(lnglat);         
        map.addOverLay(marker);

        //搜索地址
        geocode = new T.Geocoder();
        geocode.getLocation(lnglat,searchResult);

        //添加点击事件
        map.addEventListener("click",function(e){

          if(marker){
            map.clearOverLays();
          }

          //加个标记
          marker = new T.Marker(e.lnglat);         
          map.addOverLay(marker);
        
          $("#latX").val(e.lnglat.lat)
          $("#lngX").val(e.lnglat.lng)

          //点击地址，解析信息
          map.addEventListener("click", function(e){
              geocode.getLocation(e.lnglat,searchResult);
          });


        });

        //创建标注对象
        var label = new T.Label({
            text: "万易商城台州总部<div style='color:#007;'>星星电子商务产业园A3-216</div>",
            position: lnglat,
            offset: new T.Point(-10, 15)
        });
        //创建地图文本对象
        map.addOverLay(label);        

        return 1;
    };

    //关闭地图，设置坐标
    function close_map(){
      var el_latx=document.getElementById("latX");
      var el_lngx=document.getElementById("lngX");
      if(!el_latx.value || !el_lngx.value) {
        //alert('请点击地图选择一个地址!');
        //return;
      }

      var el_lat=document.getElementById("lat");
      var el_lng=document.getElementById("lng");
      if(!el_lat || !el_lng) {
        //alert('请确认页面有lat,lnt输入框!');
        //return;
      }

      el_lat.value=el_latx.value;
      el_lng.value=el_lngx.value;

      $("#mapContainer").hide();

    }

    //地址搜索
    function area_serarch(){
      //map.clearOverLays();
      var val=document.getElementById("area").value;
      geocode.getPoint(val,searchResult2);
    }


    function searchResult2(result){
      if(result.getStatus() == 0){
        map.clearOverLays();
        map.panTo(result.getLocationPoint(), 16);
        //创建标注对象
            var marker = new T.Marker(result.getLocationPoint());
            //向地图上添加标注
            map.addOverLay(marker);
      }else{
        alert("Error:"+result.getMsg());
      }      
    }

    //地点解析
    function searchResult(result){
        if(result.getStatus() == 0){
            document.getElementById("addressMsg").innerHTML = "<font style='font-weight:700'>详细地址：</font>"+result.getAddress();
            var addCom = result.getAddressComponent().addressComponent;
            var prov =addCom.province;
            var city = addCom.city;
            var county = addCom.county;
            console.log(addCom);
            document.getElementById("detailedAddress").innerHTML = prov+" "+city+" "+addCom.county;

            // var html = "<font style='font-weight:700'>详细信息如下：</font><br/>";
            // html += "<font style='font-size:12px'>此点最近地点信息："+addCom.address+"</font><br/>";
            // html += "<font style='font-size:12px'>此点距离最近地点信息距离："+addCom.address_distance+"米</font><br/>";
            // html += "<font style='font-size:12px'>此点在最近地点信息方向："+addCom.address_position+"</font><br/>";
            // html += "<font style='font-size:12px'>此点所在国家或城市或区县："+addCom.city+"</font><br/>";
            // html += "<font style='font-size:12px'>距离此点最近poi点："+addCom.poi+"</font><br/>";
            // html += "<font style='font-size:12px'>距离此点最近poi点的距离："+addCom.poi_distance+"米</font><br/>";
            // html += "<font style='font-size:12px'>此点在最近poi点的方向："+addCom.poi_position+"</font><br/>";
            // html += "<font style='font-size:12px'>距离此点最近的路："+addCom.road+"</font><br/>";
            // html += "<font style='font-size:12px'>此点距离此路的距离："+addCom.road_distance+"米</font><br/>";
            // document.getElementById("detailedAddress").innerHTML = html;
        }
        else
        {
            document.getElementById("addressMsg").innerHTML = "<font style='font-weight:700'>服务器返回状态：</font>"+result.getStatus();
            document.getElementById("detailedAddress").innerHTML = "<font style='font-weight:700'>服务器返回响应信息：</font>"+result.getMsg();
        }
    }
</script>


<script type="text/javascript">

    $(function(){

      $("#lat,#lng").on('click',function(){
        $("#mapContainer").show();//.css({"left":"10%"});
        t_map();
      })

      $("#find_user").on('click',function(){
        $.post('/index.php/user/getOne',{nameOrMobile:$("#user_id_name").val()},function(res){
          if(res.code){
            var data = res.data;
            var user_id = data.id;
            $("#user_id").val(user_id);
            $("#new_user_id").text(user_id);
            layer.msg(res.msg);
          }else{
            layer.msg(res.msg);
          }

        })
      })

      //删图
    $(".img_remove").on('click',function(){
      var src=$(this).attr('src');
      var row_id=$(this).attr('row_id');

      //询问框
      layer.confirm('是否确定删除图片?', {
        btn: ['确定','取消'] //按钮
      }, function(){
        
        $.post('/index.php/sys/img_remove',{tb:'dept_info',row_id:row_id,field:'ad_img',src:src},function(res){
            if(res.code){
                layer.msg(res.msg);
                location.reload();
            }
        })

      }, function(){
        layer.msg("好的!");
        return 0;
      });
    })

    //+图
    $('#img_add').on('click',function(){$('#file1').click()})
    //提交图片
    $("#file1").on('change',function(e){
      var el1='<input name="tb"  type="hidden" value="dept_info+ad_img" />';
      var el3='<input name="key"  type="hidden" value="dept_id" />';
      var el2='<input name="source_url" type="hidden" value="/dept/edit/id/'+$('#id').val()+'" />';
      $('#file1').after(el1).after(el2).after(el3);

      $("form").attr('action','/sys/img_add').submit();
    })

    //看图
    $(".thumb").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='height:100%'>"
        });
    })        

    })

    function doSave(){
      if(!$("#name").val()) {
        layer.msg("无效的名称(Invalid name)!");
        return 0;
      }    
      //询问框
      layer.confirm('是否确定保存?', {
        btn: ['YES','CANCEL'] //按钮
      }, function(){
        $('form').submit();
      }, function(){
        layer.msg("Cancel!");
        return 0;
      });
    }

</script>


</body>
</html>
